import { defineStore } from 'pinia'
import store from '@/store'
import { cloneDeep } from 'lodash-es'
import { encryptorPwd } from '@/utils/jsencrypt'
import { getAssetsFile } from "@/utils/index";
// import api from '@/api'
// const { login, logout, getCurrentUser } = api


export const useUserStore = defineStore('user', {
    state: () => ({
        token: '',
        userInfo: {},
        messageMsg: {
            currentMsg: {
                id: 1,
                img: getAssetsFile("down.svg"),
                name: '助手',
                intro: '帮你找到有用信息',
                index: 0,
                list: [{
                    type: 'answer',
                    message: ''
                }],
                moreQuestion: [
                    {
                        question: '问题1'
                    },
                    {
                        question: '问题2'
                    },
                    {
                        question: '问题3'
                    },
                    {
                        question: '问题4'
                    },
                ]
            },
            list: [
                {
                    id: 1,
                    img: getAssetsFile("down.svg"),
                    name: '助手',
                    intro: '帮你找到有用信息',

                },
                {
                    id: 2,
                    img: getAssetsFile("down.svg"),
                    name: '11',
                    intro: '',
                },

            ]
        }
    }),
    actions: {
        // 登录
        // async login(LoginParams) {
        //     const loginData = cloneDeep(LoginParams)
        //     loginData.userPwd = encryptorPwd(loginData.userPwd)
        //     const res = await login(loginData)
        //     this.token = res.result?.token

        // },
        // 退出登录
        // async logout() {
        //     await logout()
        //     this.hasCachePermission = false
        //     this.resetToken()
        // },
        // // 获取用户信息
        // async getUserInfo() {
        //     const res = await getCurrentUser()
        //     this.userInfo = res.result?.data || {}
        //     setUserInfo(this.userInfo)
        // },
        async getMessageInfo(key, value) {
            this.messageMsg[key] = value
        },
        // 清除token
        resetToken() {
            this.token = ''
        },

    }
})

// 当pinia未初始化之前注入使用
export const useUserStoreWithOut = () => {
    return useUserStore(store)
}
